package com.itheima.jdk7.calendarDemo;

import java.util.Calendar;

public class CalendarDemo1 {
    public static void main(String[] args) {
        // 获取一个GregorianCalendar对象
        Calendar c1 = Calendar.getInstance();
        System.out.println(c1);

//        Date d = new Date(0L);
//        c1.setTime(d);
//        System.out.println(c1);

        // 获取属性
        int year = c1.get(Calendar.YEAR);
        int month = c1.get(Calendar.MONTH) + 1;//Calendar的月份值是0-11
        int day = c1.get(Calendar.DAY_OF_MONTH);

        int hour = c1.get(Calendar.HOUR);
        int minute = c1.get(Calendar.MINUTE);
        int second = c1.get(Calendar.SECOND);
        int week = c1.get(Calendar.DAY_OF_WEEK);//返回值范围：1--7，分别表示："星期日","星期一","星期二",...,"星期六"

        System.out.println(year + "年" + month + "月" + day + "日" +
                hour + ":" + minute + ":" + second);
        System.out.println(getWeek(week));

        // set方法、add
        c1.set(Calendar.YEAR, 1998);
        c1.set(Calendar.MONTH, 3 - 1);//转换为Calendar内部的月份值
        c1.set(Calendar.DAY_OF_MONTH, 18);
        System.out.println(c1);
    }

    //查表法，查询星期几
    public static String getWeek(int w) {//w = 1 --- 7
        //做一个表(数组)
        String[] weekArray = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        //            索引      [0]      [1]       [2]      [3]       [4]      [5]      [6]
        //查表
        return weekArray[w - 1];
    }
}
